package com.ctshk.sapp.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.NoticePositionDTO;
import com.ctshk.rpc.cms.dto.NoticePositionListDTO;
import com.ctshk.rpc.cms.req.NoticePositionAddReq;
import com.ctshk.rpc.cms.req.NoticePositionQueryReq;
import com.ctshk.rpc.cms.req.NoticePositionUpdateReq;
import com.ctshk.rpc.cms.req.SelectAllQueryReq;
import com.ctshk.rpc.cms.service.INoticePositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 公告位置管理表 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "公告位置管理", tags = "公告位置管理")
@RestController
@RequestMapping("/notice-position")
public class NoticePositionController extends BaseController {
    @DubboReference
    private INoticePositionService noticePositionService;

    @ApiOperation(value = "新增公告位", notes = "新增公告位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid NoticePositionAddReq req) {
        return noticePositionService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询公告位作为下拉列表", notes = "查询公告位作为下拉列表")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getSelectList")
    public Result<List<NoticePositionDTO>> getSelectList() {
        return noticePositionService.getSelectList();
    }

    @ApiOperation(value = "查询公告位作为下拉列表2", notes = "查询公告位作为下拉列表2")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getSelectListAll")
    public Result<PageResponse<NoticePositionDTO>> getSelectList2(@RequestBody @Valid SelectAllQueryReq req) {
        return noticePositionService.getSelectList2(req);
    }

    @ApiOperation(value = "查询公告列表", notes = "查询公告列表")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/getList")
    public Result<PageResponse<NoticePositionListDTO>> getList(@RequestBody @Valid NoticePositionQueryReq req) {
        return Result.success(noticePositionService.getList(req));
    }

    @ApiOperation(value = "查询公告位", notes = "查询公告位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/getNoticePositionById/{id}")
    public Result<NoticePositionListDTO> getNoticePositionById(@PathVariable("id") Long id) {
        return noticePositionService.getNoticePositionById(id);
    }

    @ApiOperation(value = "修改公告位", notes = "修改公告位")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid NoticePositionUpdateReq req) {
        return noticePositionService.update(req, getCurrentUser(getRequest()));
    }
}
